package rateexchange.client.ui;





import rateexchange.client.RateExchangeConstants;
import rateexchange.client.place.RatesTablePlace;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class RateViewImpl extends Composite implements RateView{

	private RateHandler handler;
	
	private RateEditor 	editor;
	
	private RateExchangeConstants constants = GWT.create(RateExchangeConstants.class);
	
	public RateViewImpl(){
		VerticalPanel panel = new VerticalPanel();
		HorizontalPanel hpanel = new HorizontalPanel();
		
		editor = new RateEditor();
		
		
		Button save = new Button(constants.save());
		save.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				handler.save();
				
			}
		});
		Button cancel = new Button(constants.cancel());
		cancel.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent event) {
				handler.goTo(new RatesTablePlace("list"));
				
			}
		});
		
	
	hpanel.add(save);
	hpanel.add(cancel);
	panel.add(editor);
	panel.add(hpanel);
	initWidget(panel);
	}
	
	
	public void setPresenter(RateHandler handler){
		this.handler = handler;
	}
	
	public RateEditor getEditor(){
		return editor;
	}
	
	public void save() {
		handler.save();
		}

}
